const templateUrl = require('@utils/util-apis')['templateUrl']

module.exports = {

	editMethod() {
		let {
			store,
			dailogComp,
			templateForm,
			parameterList,
			tableComp,
		} = this
		let formDialog = dailogComp.formDialog
		if (!store.isLock) {
			formDialog.dialog('close')
			return false
		}
		let isValid = templateForm.form('validate');
		if (!isValid) {
			$.messager.progress('close');
			return false
		}
		let url = templateUrl[`${store.editType}Url`]
		let jsonData = parameterList.treegrid('getData')
		if (jsonData.length < 1) {
			$.messager.alert({
				title: '提示',
				msg: '模板为空！',
			})
			return false
		}
		$.messager.progress();
		templateForm.form('submit', {
			url,
			onSubmit(params) {
				params.template = JSON.stringify(jsonData)
				if (store.updateTemplate && store.updateTemplate.id)
					params.id = store.updateTemplate.id
			},
			success(result) {
				$.messager.progress('close');
				tableComp.datagrid('reload')
				formDialog.dialog('close')
			},
		})
	},
}